<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">群众姓名:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.userName" placeholder="请填写" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">联系方式:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.userMobile" placeholder="请填写" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">宣传内容:</div>
        <div class="input-item">
          <a-select ref="select" v-model="queryParam.columnContent" placeholder="请选择">
            <a-select-option v-for="(item, index) in publicize_column_type" :key="index" :value="item.value">
              {{ item.text }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">宣传民警:</div>
        <div class="input-item">
          <a-input :maxLength="30" clearable v-model="queryParam.policeName" placeholder="请填写" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">宣传时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="btn-wrap">
        <a-button
          class="searchBtn"
          @click="searchQuery(queryParam.createTime_begin, queryParam.createTime_end)"
          type="primary"
        >
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template v-slot:action="records">
          <span class="operation deatil-color" @click="detailHandle(records)">详情 </span>
        </template>
      </a-table>
    </div>

    <detailModal ref="detailModal" />
  </div>
</template>
<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mapState } from 'vuex'
import { ajaxGetDictItems } from '@/api/api'
import detailModal from './publicityRecord/detailModal'
export default {
  name: 'visitor-alreadyVisited',
  components: { startEndTime, detailModal },
  mixins: [JeecgListMixin],
  computed: {
    ...mapState({
      isPoliceAgencyId: (state) => state.user.isPoliceAgencyId,
    }),
  },
  watch: {
    isPoliceAgencyId: {
      handler(v) {
        this.queryParam.policeAgencyId = v.id ? v.id : ''
        this.searchQuery()
      },
    },
  },
  data() {
    return {
      url: {
        list: '/common/publicize_record/page',
        tree: true,
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '姓名',
          dataIndex: 'userName',
          ellipsis: true,
          width: 300,
          align: 'center',
        },
        {
          title: '联系方式',
          dataIndex: 'userMobile',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '宣传内容',
          dataIndex: 'columnMemo',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '宣传民警',
          dataIndex: 'policeName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '宣传时间',
          width: 200,
          dataIndex: 'publicizeTime',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
        },
      ],
      publicVisible: false,
      disableMixinCreated: true,
      publicize_column_type: [],
    }
  },
  mounted() {
    this.getDist()
  },
  methods: {
    async getDist() {
      let { result: publicize_column_type } = await ajaxGetDictItems({ code: 'publicize_column_type' })
      this.publicize_column_type = publicize_column_type
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.createTime_begin = this.$moment(v).valueOf()
      } else {
        this.queryParam.createTime_end = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.createTime_begin = null
        this.queryParam.createTime_end = null
      }
    },

    detailHandle(records) {
      this.$refs.detailModal.show(records)
    },
  },
}
</script>
